package com.sfh.appversion.base.exception;

import com.sfh.appversion.base.errorcode.IErrorCode;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Optional;

/**
 * 抽象项目中三类异常体系，客户端异常、服务端异常以及远程服务调用异常
 *
 */
@Getter
public abstract class AbstractException extends RuntimeException {

    public final String code;

    public final String msg;

    public AbstractException(String message, Throwable throwable, IErrorCode errorCode) {
        super(message, throwable);
        this.code = errorCode.code();
        this.msg = Optional.ofNullable(StringUtils.hasLength(message) ? message : null).orElse(errorCode.msg());
    }
}